<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>投标</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="./css/styleold.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript">
        function closeWin(){
            var setSele = 'randomSwitchBtn(2);';
            api.execScript({
                name: 'root',
                script: setSele,
            });
            api.closeToWin({
                name: 'root'
            });
        };
    </script>
</head>
<body>
    <!-- 头部 -->
    <header class="aui-bar aui-bar-nav pos" id="topbar">
        <a class="aui-pull-left aui-btn" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">回款计划</div>
    </header>
    <div class="header-d"></div>

    <!-- 投标 -->
    <div class="toubiao">
        <ul>
            <div id="list">
<!--                 <li>
                    <h3>-</h3>
                    <span>投标金额<p>￥-</p></span>
                    <span>期限<p>-个月</p></span>
                    <span>利息<p>-%</p></span>
                    <div class="toubiao-btn">
                        <a>查看详情</a>
                    </div>
                </li> -->
            </div>
        </ul>
    </div>
    <script type="text/template" id="template">
        {{~it:value:index}}
        <li>
            <h3>{{=value.name}}-{{=value.deal_sn}}</h3>
            <span>投标金额<p>￥{{=value.money}}</p></span>
            <span>期限<p>{{=value.repay_time}}个月</p></span>
            <span>利息<p>{{=value.rate}}%</p></span>
            <div class="toubiao-btn" onclick="my_repay_plan({{=value.id}});">
                <a>查看详情</a>
            </div>
        </li>
        {{~}}
    </script>

    <script type="text/javascript">
     apiready = function(){
        // api.addEventListener({
        //     name: 'keyback'
        // }, function(ret, err) {
        //     closeWin();
        // });
        updateData();

    };

    // 更新数据,模板函数
    function updateData(){
        // 进度提示框
        api.showProgress({
            title: '努力加载中...',
            text: '请稍等...',
            modal: false
        });

        var userid = $api.getStorage('userid');
        api.ajax({
            url: webAddress + '/index.php?ctl=app_user_center&act=repay_index',
            method: 'post',
            data: {
                values: {
                    user_id: userid,
                },
            }
        },function(ret, err){
            if (ret) {
                // var ret = $api.jsonToStr(ret);
                // alert(ret);
                // 关闭下拉刷新控件
                // api.refreshHeaderLoadDone();
                api.hideProgress();
                if (ret.status == 0) {
                    alert(ret.info);
                    return false;
                }else{
                    var data = ret.list;
                    if (data) {
                        templateFun(data);
                    }else{
                        var list = $api.byId('list');
                        list.innerHTML = '<div class="login-list-no">无回款计划</div>';
                    }
                }
            } else {
                alert(err.msg);
        // api.refreshHeaderLoadDone();
        api.hideProgress();
    }
});
    };

    // 模板赋值函数
    function templateFun(data){
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var user = $api.byId('list');
        $api.html(user, html);
    }

    function my_repay_plan(id){
        api.openWin({
            name: 'my_repay_plan',
            url: './my_repay_plan.html',
            pageParam: {
                id: id,
            }
        });

        // var delay = 0;
        // if (api.systemType != 'ios') {
        //     // delay = 300;
        // }

        // api.openWin({
        //     name: 'my_repay_plan',
        //     url: './my-repay-plan.html',
        //     bounces: false,
        //     delay: delay,
        //     slidBackEnabled: true,
        //     vScrollBarEnabled: false,
        //     progress: {
        //         type: "page"
        //     },
        //     pageParam: {
        //         id: id,
        //     }
        // });
    }

    // 下拉刷新
    function pullRefresh(){
        api.setRefreshHeaderInfo({
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
        }, function(ret, err) {
            //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
            updateData();
        });
    }

    // 上拉加载
    function pullLoading(){
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err){
           updateData();
       });
    }

    // 加载状态控件
    function showProgress(){
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '请稍后...',
            modal: false
        });
    }
</script>
</html>
